package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.context.BaseContext;
import com.itheima.domain.dto.UserDTO;
import com.itheima.domain.entity.User;
import com.itheima.domain.vo.UserVO;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**
     * 用户登录
     * @param userDTO
     * @return
     */
    @Override
    public User login(UserDTO userDTO) {
        return userMapper.selectByUsername(userDTO);
    }

    /**
     * 获取用户信息
     * @return
     */
    @Override
    public UserVO userInfo() {
        Long id = BaseContext.getCurrentId();
        User user = userMapper.selectById(id);
        return UserVO.builder()
                .id(user.getId())
                .username(user.getUsername())
                .city(user.getCity())
                .category(user.getCategory())
                .education(user.getEducation())
                .experience(user.getExperience())
                .build();
    }

    @Override
    public void update(UserDTO userDTO) {
        Long id=BaseContext.getCurrentId();
        userMapper.update(userDTO,id);
    }
}
